package com.shanghaionstar.smart.widget;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.FrameLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.shanghaionstar.R;

public class NotifyBindDialog extends Dialog {
    private ViewHolder holder;
    private Context context;

    public NotifyBindDialog(Context context) {
        this(context, R.style.Theme_Dialog_NoTitleBar);
    }

    public NotifyBindDialog(Context context, int theme) {
        super(context, theme);
        holder = new ViewHolder();
        this.context = context;
        View view = View.inflate(context, R.layout.notify_bind_dia, null);
        holder.init(view);
        setContentView(view);
        setGravity();
        setWidthHeight();
        setCanceledOnTouchOutside(false);
        holder.dismissTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                NotifyBindDialog.this.dismiss();
            }
        });
    }


    /**
     * 居中
     */
    private void setGravity() {
        Window window = getWindow();
        window.setGravity(Gravity.CENTER);
    }

    /**
     * 横向全屏
     */
    private void setWidthHeight() {
        WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        int width = wm.getDefaultDisplay().getWidth() * 2 / 3;
//        int height = wm.getDefaultDisplay().getHeight() *2/ 3;
        int height = (int) (280 * context.getResources().getDisplayMetrics().density);
        FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(width, height);
        holder.notifyRl.setLayoutParams(lp);
    }


    public class ViewHolder {
        RelativeLayout notifyRl;
        TextView dismissTv;

        public void init(View view) {
            notifyRl = (RelativeLayout) view.findViewById(R.id.notify_rl);
            dismissTv= (TextView) view.findViewById(R.id.dismiss_tv);
        }
    }


}
